require('../../assets/css/index.less');
require('../../assets/css/basic.less');

// 当前页面样式
require('./addtrends.less');
// 小图标
require('../../assets/fonts/iconfont.css');
// 工具函数 utils
const dom = require('../../utils/dom');
// weui
require("../../lib/weui/weui.css");
var weui = require("../../lib/weui/weui.js");
const https = require('../../utils/https');

//
dom.ready(function() {
    // dom.creatfoot('circle');
    dom.addEvent(".cloBtn", 'click', function() {
            location.href = './circle.html'
        })
        //


    var provinceData;
    dom.addEvent("#provinceBtn", "click", function() {
        https.get("/api/shared/province", function(res) {
            let { errno, data } = res;
            if (errno == 0) {
                // console.log(data);
                var copeData = data.map(v => {
                    return {
                        value: v.id,
                        label: v.name
                    }
                })
                weui.picker(copeData, {
                    onConfirm: function(result) {
                        // console.log(result[0]);
                        dom.getEle("#provinceBtn").innerHTML = result[0]['label'];
                        provinceData = result[0]

                    },
                    title: '选择地址(省份)',
                    showClose: false
                });
            }
        })
    });
    dom.addEvent("#cityBtn", "click", function() {
        if (provinceData) {
            https.get("/api/shared/city?provinceId=" + provinceData.value, function(res) {
                let { errno, data } = res;
                if (errno == 0) {
                    // console.log(data);
                    var cityData = data.map(v => {
                        return {
                            value: v.id,
                            label: v.name
                        }
                    })
                    weui.picker(cityData, {
                        onConfirm: function(result) {
                            dom.getEle("#cityBtn").innerHTML = result[0]['label'];
                            cityTxt = result[0];
                            console.log(cityTxt);
                        },
                        title: '选择城市',
                        showClose: false
                    });
                }

            })

        } else {
            weui.alert("请先选择省份")
        }
    });

    //照片
    dom.addEvent(".adBtn", "click", function() {
        dom.getEle(".fileBtn").click()
    })
    dom.addEvent(".fileBtn", "change", function() {
        // console.log(this);
        var file = this.files[0];
        dom.upLoadPic("/api/shared/uploadPortrait", 'file', file, function(res) {
            var { errno, data } = res;
            if (errno == 0) {
                dom.getEle(".imgurl").src = 'http://fitness.h5.itsource.cn:3701' + data.url
            }
        })
    })
})